package com.freeSoft;

import java.io.File;
import java.sql.Types;
import java.util.Properties;

public class Util {
	public static String OUTPUT_DIR="output.dir";
	public static String PROJECT_NAME="project.name";
	public static String CORE_NAME = "-core";
	public static String WEB_NAME = "-web";
	public static String PROP_BEAN_PATH = "model.path";
	public static String PROP_DAO_PATH="dao.path";
	public static String PROP_SERVICE_PATH="service.path";
	public static String PROP_SERVICE_IMPL_PATH="service.impl.path";
	public static String PROP_DAO_IMPL_PATH="dao.impl.path";
	public static String PROP_ACTION_PATH="com.windfone.web.action";
	public static String javaPackToFilePath(String packPath ){
		if ( packPath!=null)
			return packPath.replace(".", File.separator);
		else 
			return null;
	}
	
	
	public static String[] JDBC_TYPE_MAP ={"CHAR","VARCHAR","LONGVARCHAR","NUMERIC","DECIMAL","BIT","TINYINT","SMALLINT","INTEGER",
							"BIGINT","REAL","FLOAT","DOUBLE","BINARY","VARBINARY","LONGVARBINARY","DATE","TIME","TIMESTAMP"};
	public static String[] JAVA_TYPE_MAP={"String","String","String","BigDecimal","BigDecimal","boolean","byte","short","int",
			"long","float","double","double","byte[]","byte[]","byte[]","Date","Time","Timestamp"};
	public static String[] JAVA_IMPORT_MAP={"","","","java.math.BigDecimal","java.math.BigDecimal","","","","",	"","","","","","","","java.sql.Date","java.sql.Time","java.sql.Timestamp"};
	public static String[] JAVA_TYPE_MAP_JDBC_JAVA={"String","String","java.math.BigDecimal","boolean","byte","short","int","long","float","double","byte[]","byte[]","Date","Time","Timestamp"};
	public static String[] JAVA_TYPE_MAP_JDBC_JDBC={"VARCHAR","LONGVARCHAR","NUMERIC","BIT","TINYINT","SMALLINT","INTEGER","BIGINT","REAL","DOUBLE","VARBINARY","LONGVARBINARY","DATE","TIME","TIMESTAMP"};
 
	public static String changeJDBCTypeToJavaType(String jdbcTypeName){
		String typeName = jdbcTypeName.toUpperCase();
		String rtv = "";
		for(int i=0;i<JDBC_TYPE_MAP.length;i++){
			if ( JDBC_TYPE_MAP[i].equals( typeName )){
				rtv = JAVA_TYPE_MAP[i];
				break;
			}
		}
		return rtv;
	}
	
	public static String getImportPath(String jdbcTypeName){
		String typeName = jdbcTypeName.toUpperCase();
		String rtv = "";
		for(int i=0;i<JDBC_TYPE_MAP.length;i++){
			if ( JDBC_TYPE_MAP[i].equals( typeName )){
				rtv = JAVA_IMPORT_MAP[i];
				break;
			}
		}
		return rtv;
	}
	
	public  static   String   getDataType(int   type,int   scale){  
		String   dataType="";  
        switch(type){  
        	case   Types.LONGVARCHAR:   //-1  
        		dataType="Long";  
        		break;  
        	case   Types.CHAR:         //1  
        		dataType="Character";  
        		break;  
        	case   Types.INTEGER:         //1  
        		dataType="int";  
        		break;  
        	case   Types.NUMERIC:   //2  
        		switch(scale){  
        			case   0:  
        				dataType="Number";  
        				break;  
        			case   -127:  
        				dataType="Float";  
        				break;  
        			default:  
        				dataType="Number";  
        		}  
        		break;  
        	case   Types.VARCHAR:     //12  
        		dataType="String";  
        		break;  
        	case   Types.DATE:     //91  
        		dataType="Date";  
        		break;  
        	case   Types.TIMESTAMP:   //93  
        		dataType="Date";  
        		break;  
        	case   Types.BLOB   :  
        		dataType="Blob";  
        		break;  
        	default:  
        		dataType="String";  
        }  
       return   dataType;  
    }
	
	public static String changeName(String name){
		String str = name;
		int index = str.indexOf("_");
		if ( index != -1 ){
			String str1 = str.substring(0, index);
			String str2 = str.substring(index+1, str.length());
			str2=str2.substring(0, 1).toUpperCase()+str2.substring(1, str2.length());
			str = str1+str2;
			str =changeName(str );
		}
		return str;
	}
	public static String getOutputDir(Properties prop){
		String outputDir = prop.getProperty(Util.OUTPUT_DIR);
		if (outputDir.substring(outputDir.length()-1, outputDir.length()).equals("/") ||
		    outputDir.substring(outputDir.length()-1, outputDir.length()).equals("\\")){
			
		}else {
			outputDir = outputDir + File.separator;
		}
		return outputDir;
	}
	
	public static String changeInitialToLower(String beanName){
		String tmp = beanName.substring(0, 1).toLowerCase() + beanName.substring(1, beanName.length());
		return tmp;
	}
	public static String changeInitialToUpper(String beanName){
		String tmp = beanName.substring(0, 1).toUpperCase() + beanName.substring(1, beanName.length());
		return tmp;
	}
	public static void main(String args[]){
		String str = "com.freesoft.model";
		String str2 = File.separator;
		System.out.println( str.replace(".",str2));
		String  name = "Mes_server_info";
		System.out.println( changeName(name) );
	}
}
